function getQueryString(name) {
    var svalue  = location.href.match(new RegExp("[\?\&]" + name + "=([^\&]*)(\&?)","i"));
    return svalue ? svalue[1] : svalue;
}
angular.module('newslist.controller',[])
// .run(function($ionicPlatform) {
  .run(['$ionicPlatform','$ionicPopup','$rootScope','$location','$ionicHistory','$ionicViewSwitcher',function($ionicPlatform,$ionicPopup,$rootScope,$location,$ionicHistory,$ionicViewSwitcher){

  /*注册返回事件*/
  $ionicPlatform.registerBackButtonAction(function(e){
      $state.go("tab.maincontent");
    return false;
  },100);//501表示优先级  100~999之间

}])


  .controller('newslistCtrl',['$scope','$timeout' ,'$localstorage','$ionicPopup','newslistService','$state','loginService',function($scope,$timeout,$localstorage,$ionicPopup,newslistService,$state,loginService){

    $scope.params={};
    $scope.NewsJsonData=[];
    $scope.params=newslistService.getParams();
    $scope.visible=true; //初始
     $scope.doRefresh = function() {
            var typeid=  getQueryString('typeid');
            newslistService.get_newslistInfo(typeid).then(function(data){
                              $scope.NewsJsonData=data;
                            },function(error){
                              var alertPopup=$ionicPopup.alert({
                                title:'获取在网导航失败！',
                                template:"异常错误",
                                okText: '确定', // String (默认: 'OK')。OK按钮的文字。
                                okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
                              });
                            });
         };
    $scope.$on('$ionicView.enter', function(event, data) {
          console.log("主页进来了");
          $scope.doRefresh();
    });
    $scope.goBack = function(){
      $state.go("tab.maincontent");
    }
  }]);
